package com.booter.gateway.filter;

import org.apache.commons.lang3.StringUtils;
import org.reactivestreams.Publisher;
import org.springframework.cloud.gateway.filter.factory.rewrite.RewriteFunction;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Base64;

public class CustomRewriteFunction implements RewriteFunction<String, String> {
    @Override
    public Publisher<String> apply(ServerWebExchange exchange, String s) {
        if (StringUtils.isNotBlank(s)) {
            s = new String(Base64.getDecoder().decode(s));
            return Mono.just(s);
        }
        return Mono.just("");
    }
}
